#pragma once
#include"GlobalDefines.h"

struct TexCoord2
{
   float tu, tv;
};


struct Point3D
{
   float x, y, z;
};


enum enQ3LumpOffsets
{
   iEnitiesOffset = 0,
   iTextureOffset,
   iPlanesOffset,
   iNodesOffset,
   iLeafOffset,
   iLeafFacesOffset,
   iLeafBrushesOffset,
   iModelsOffset,
   iBrushesOffset,
   iBrushesSidesOffset,
   iVerticesOffset,
   iMeshVerticesOffset,
   iShaderFilesOffset,
   iFacesOffset,
   iLightMapsOffset,
   iLightVolumeOffset,
   iVisibleDataOffset,
   iMaxLumpsOffset
};


struct Q3Header
{
   char bspID[4];
   int version;
};


struct Q3FileLump
{
   int offset;
   int length;
};


struct Q3Texture
{
   char file[64];
   int flags;
   int contents;
};


struct Q3Face
{
   int texID;
   int effect;
   int type;
   int startVertexIndex;
   int totalVertices;
   int meshVertexIndex;
   int totalMeshVertices;
   int lightmapID;
   int lightMapCorner[2];
   int lightMapSize[2];
   Point3D lightMapPos;
   Point3D lightMapVectors[2];
   Point3D normal;
   int size[2];
};


struct Q3Vertex
{
   Point3D vertex;
   TexCoord2 texCoord;
   TexCoord2 lightmapCoord;
   Point3D normal;
   unsigned char color[4];
};


struct Q3LightMap
{
   unsigned char lightMap[128][128][3];
};


class WorldMap
{
   public:
      WorldMap() : m_totalTextures(0), m_totalVertices(0),
                    m_totalLightMaps(0), m_totalFaces(0), m_faces(0),
                    m_vertices(0), m_textures(0), m_lightMaps(0) {}
      ~WorldMap()
      {
         Shutdown();
      }

      bool LoadLevel(char *filename);
	  bool initWorldMap();
      void SwapAxis();
      void Shutdown();
	  void Render();


      int m_totalTextures;
      int m_totalLightMaps;
      int m_totalVertices;
      int m_totalFaces;
	  //BSPTree<WayPoint*> m_wayPoint;

      Q3Face *m_faces;
      Q3Vertex *m_vertices;
      Q3Texture *m_textures;
      Q3LightMap *m_lightMaps;
};